﻿using System;
using System.Collections.Generic;

namespace FSM
{
    /// <summary>
    /// 有限状态机管理器接口
    /// </summary>
    public interface IFsmManager
    {
        /// <summary>
        /// 获取有限状态机的数量
        /// </summary>
        int Count { get; }
        /// <summary>
        /// 检查是否存在有限状态机
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        bool HasFsm<T>() where T : class;

        /// <summary>
        /// 检查是否存在有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <returns></returns>
        bool HasFsm(Type ownerType);

        /// <summary>
        /// 检查是否存在有限状态机
        /// </summary>
        /// <param name="name"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        bool HasFsm<T>(string name) where T : class;

        /// <summary>
        /// 检查是否存在有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        bool HasFsm(Type ownerType, string name);

        /// <summary>
        /// 获取有限状态机
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> GetFsm<T>() where T : class;

        /// <summary>
        /// 获取有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <returns></returns>
        FsmBase GetFsm(Type ownerType);

        /// <summary>
        /// 获取有限状态机
        /// </summary>
        /// <param name="name"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> GetFsm<T>(string name) where T : class;
        
        /// <summary>
        /// 获取有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        FsmBase GetFsm(Type ownerType, string name);
        /// <summary>
        /// 获取所有有限状态机
        /// </summary>
        /// <returns></returns>
        FsmBase[] GetAllFsms();
        /// <summary>
        /// 获取所有有限状态机
        /// </summary>
        /// <param name="results"></param>
        void GetAllFsms(List<FsmBase> results);

        /// <summary>
        /// 创建有限状态机
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="states"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> CreateFsm<T>(T owner, params FsmState<T>[] states) where T : class;
        
        /// <summary>
        /// 创建有限状态机
        /// </summary>
        /// <param name="name"></param>
        /// <param name="owner"></param>
        /// <param name="states"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> CreateFsm<T>(string name, T owner, params FsmState<T>[] states) where T : class;

        /// <summary>
        /// 创建有限状态机
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="states"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> CreateFsm<T>(T owner, List<FsmState<T>> states) where T : class;
        
        /// <summary>
        /// 创建有限状态机
        /// </summary>
        /// <param name="name"></param>
        /// <param name="owner"></param>
        /// <param name="states"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IFsm<T> CreateFsm<T>(string name, T owner, List<FsmState<T>> states) where T : class;
        
        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        bool DestroyFsm<T>() where T : class;
        
        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <returns></returns>
        bool DestroyFsm(Type ownerType);

        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        bool DestroyFsm<T>(string name) where T : class;

        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        /// <param name="ownerType"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        bool DestroyFsm(Type ownerType, string name);

        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        bool DestroyFsm<T>(IFsm<T> fsm) where T : class;

        /// <summary>
        /// 销毁有限状态机
        /// </summary>
        bool DestroyFsm(FsmBase fsm);
    }
}